package cn.canxin.core.controller;

import cn.canxin.common.web.tools.NetworkTools;
import com.taobao.api.ApiException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/10.
 */
@Scope("prototype")
@Controller
@RequestMapping("/comnControl")
public class ComnControl {

    @ResponseBody
    @RequestMapping(params = "getMessageAuthenticationCode",method = RequestMethod.GET)
    public Map getMessageAuthenticationCode(HttpServletRequest resquest, @RequestParam String mobileNo) throws ApiException {
        String code = NetworkTools.generateRandomNumber();

        String sessionId =  resquest.getSession().getId();
        Map params = new HashMap();
        params.put("mobileNo",mobileNo);
        params.put("code",code);
        NetworkTools.sendMessageAuthCode(mobileNo,code);
        resquest.getSession().setAttribute(sessionId,params);
        Map result = new HashMap();
        result.put("result","ok");
        return result;
    }
}
